"""
python的继承
"""
from abc import abstractmethod, ABC


class C(ABC):  # SECTION 只有继承了ABC类,才会强制 实现抽象方法
    @abstractmethod
    def say(self):
        """
        自我描述
        """
        print("C super Say")


class CSub(C):
    def say(self):
        # 仍然可以继承
        super().say()
        print("C sub Say")

    def sayx(self):
        print("say something")


# @C.register
@CSub.register
class VC:
    def sayx(self):
        print("通过ABC子类的register 注册的虚拟子类")


def test():
    """
    >>> test()
    say something
    C super Say
    C sub Say
    通过ABC子类的register 注册的虚拟子类
    True
    True
    虚拟子类不会获得任何超类的方法或属性!
    True
    """
    cs = CSub()
    cs.sayx()
    cs.say()
    vc = VC()
    vc.sayx()
    print(issubclass(CSub, C))
    print(issubclass(VC, C))
    try:
        vc.say()
    except AttributeError:
        print("虚拟子类不会获得任何超类的方法或属性!")
        pass
    print(issubclass(VC, CSub))


if __name__ == "__main__":
    import doctest

    print("抽象类-abstract-base 测试开始")
    (ff, tt) = doctest.testmod()
    print("测试结束:统计-失败{},总计{}".format(ff, tt))
    print("√" * tt if tt > 0 and not ff else "无测试" if not ff else "×" * ff)
